home *** CD-ROM | disk | FTP | other *** search
/ Deutsche Edition 1 / Deutsche Edition 1.iso / amok / amok_lha / amok03.lha / IFFLoad_1.1 / LoadBody.asm < prev    next >
Assembly Source File  |  1993-08-15  |  7KB  |  195 lines

  1. ;----------------------------------------------------------------------------
  2. ;    :Program.    LoadBody.asm
  3. ;    :Author.     Fridtjof Siebert
  4. ;    :Address.    Nobileweg 67, D-7-Stgt-40
  5. ;    :Phone.      0711/822509
  6. ;    :Shortcut.   [fbs]
  7. ;    :Version.    .01
  8. ;    :Date.       06-Jun-88
  9. ;    :Copyright.  PD
  10. ;    :Language.   68000-Assembler
  11. ;    :Translator. Profimat.
  12. ;    :Imports.    none.
  13. ;    :UpDate.     none.
  14. ;    :Contents.   Prozedur zum Laden des BODYs eines gepackten ILBM-Bildes.
  15. ;    :Remark.     There is some MODULA on the right to improve clearity.
  16. ;----------------------------------------------------------------------------
  17. ;
  18. ; PROCEDURE LoadBody(GetData: PROC; Buffer,BitMapPtrs: ADDRESS; LineLength,
  19. ;                    LineWidth: LONGINT; Height,Depth: INTEGER;
  20. ;                    ExtraPlane: BOOLEAN);
  21. ;
  22. ;------  Values from caller:  ------
  23. ;
  24. GetData    equr A2;
  25. Buffer     equr A3;
  26. BitMapPtrs equr A4;
  27. LineLength equr D2;
  28. LineWidth  equr D3;
  29. Height     equr D5;
  30. Depth      equr D4;
  31. ExtraPlane equr D6;
  32. ;
  33. ;------  Variables:  ------
  34. ;
  35. Line       equr D5;
  36. Plane      equr D6;
  37. Byte       equr D7;
  38. Location   equr A5;
  39. Right      equr A6;
  40. ;
  41. Scratch    equr D0;
  42. count      equr D1;
  43. ;
  44. ;----------------------------------------------------------------------------
  45. ;
  46. ;------  Save some data (there aren't enough Registers):  ------
  47. ;
  48.   lea     Extra,A0;
  49.   move.w  ExtraPlane,(A0);
  50.   lea     AnzLines,A0;
  51.   move.w  Height,(A0);
  52. ;
  53. ;------  Get Data from File (512 Bytes):  ------
  54. ;
  55.   movem.l D2-D7/A2-A6,-(sp);
  56.   jsr     (GetData);                       GetData();
  57.   movem.l (sp)+,D2-D7/A2-A6;
  58.   move    #0,count;                        count := 0;
  59. ;
  60. ;------  Initialize Loop for Lines:  ------
  61. ;
  62.   move    #0, Line;                        Line := 0;
  63. ;
  64. LineLoop: ;                                REPEAT
  65. ;
  66. ;-------  Initialize Loop for Planes:  ------
  67. ;
  68.   move    #0, Plane;                         Plane := 0;
  69. ;
  70. PlaneLoop: ;                                 REPEAT
  71. ;
  72. ;------  Calculate Position within Image:  ------
  73. ;
  74.     move    LineWidth,Scratch;
  75.     mulu    Line,Scratch;
  76.     move.l  Scratch,Location;
  77.     asl     #2,Plane;
  78.     add.l   0(BitMapPtrs,Plane),Location;      Location := BitMapPtrs^[Plane];
  79.     asr     #2,Plane;
  80. ;
  81. ;------  Calculate Position after the Plane-Loop:  ------
  82. ;
  83.     move.l  Location,Right;
  84.     add.l   LineLength,Right;                  Right := Location + LineLength;
  85. ;
  86. ;------  Let's read the data:  ------
  87. ;
  88. ReadRepeat: ;                                  REPEAT
  89. ;
  90. ;------  Get 1 Byte and check it:  ------
  91. ;
  92.       bsr     GetByte;                           Scratch := GetByte();
  93.       cmp.b   #128,Scratch;
  94.       bhi.s   RepeatNext;
  95.       beq.s   DoRien;                            IF Scratch<128 THEN
  96. ;
  97. ;------  Get Next Scratch+1 Bytes Liberately:  ------
  98. ;
  99.       move.b  Scratch,Byte;                        Byte := Scratch;
  100. GetMany: ;                                           REPEAT
  101.         bsr     GetByte;                             Scratch := GetByte();
  102.         move.b  Scratch,(Location);                  Location^ := Scratch;
  103.         addq.l  #1,Location;                         INC(Location)
  104.         subq.b  #1,Byte;                             DEC(Byte);
  105.         bpl.s   GetMany;                           UNTIL Byte<0;
  106.         bra.s   DoRien;
  107. ;
  108. ;------  Get Next Byte and Repeat it 257-Scratch times:  ------
  109. ;
  110. RepeatNext: ;                                    ELSIF Scratch>128 THEN
  111.       move.b  Scratch,Byte;                        Byte := Scratch;
  112.       bsr     GetByte;                             Scratch := GetByte();
  113. RepeatIt: ;                                        REPEAT;
  114.         move.b  Scratch,(Location);                  Location^ := Scratch;
  115.         addq.l  #1,Location;                         INC(Location);
  116.         addq.b  #1,Byte;                             INC(Byte);
  117.         cmp.b   #1,Byte;                           UNTIL Byte=1;
  118.         bne.s   RepeatIt;                        END;
  119. ;
  120. ;------  Compare new Location with first of next Line:  ------
  121. ;
  122. DoRien:
  123.       cmp.l   Location,Right;                  UNTIL Location>=Right;
  124.       bhi.s   ReadRepeat;
  125. ;
  126. ;------  Increament Plane and repeat Loop:  ------
  127. ;
  128.     addq    #1,Plane;                          INC(Plane);
  129.     cmp     Depth,Plane;                     UNTIL Pland>=Depth;
  130.     blo.s   PlaneLoop;
  131. ;
  132. ;------  Get Extra-Plane if exists:  ------
  133. ;
  134.     lea     Extra,A0;
  135.     tst     (A0);
  136.     beq.s   NoExtraPlane;                    IF ExtraPlane THEN
  137. ; next lines are equal to them above, but the data isn't saved:
  138.     move.l  #0,Location;                       Location := NIL;
  139. ExReadRepeat: ;                                REPEAT
  140.       bsr     GetByte;                           Scratch := GetByte();
  141.       cmp.b   #128,Scratch;
  142.       bhi.s   ExRepeatNext;
  143.       beq.s   ExDoRien;                          IF Scratch<128 THEN
  144.       move.b  Scratch,Byte;                        Byte := Scratch;
  145. ExGetMany: ;                                       REPEAT
  146.         bsr     GetByte;                             Scratch := GetByte();
  147.         addq.l  #1,Location;                         INC(Location)
  148.         subq.b  #1,Byte;                             DEC(Byte);
  149.         bpl.s   ExGetMany;                         UNTIL Byte<0;
  150.         bra.s   ExDoRien;
  151. ExRepeatNext: ;                                  ELSIF Scratch>128 THEN
  152.       move.b  Scratch,Byte;                        Byte := Scratch;
  153.       bsr     GetByte;                             Scratch := GetByte();
  154. ExRepeatIt: ;
  155.         add.l   #257,Location;                     INC(Location,257);
  156.         and.l   #$FF,Byte
  157.         sub.l   Byte,Location;                     DEC(Location,Byte);
  158. ExDoRien:
  159.       cmp.l   Location,LineLength;
  160.       bhi.s   ExReadRepeat;                    UNTIL Location>=LineLength;
  161. NoExtraPlane: ;                              END;
  162. ;
  163. ;------  Increament Line and repeat Loop:  ------
  164. ;
  165.   addq    #1,Line;                           INC(Line);
  166.   lea     AnzLines,A0;
  167.   cmp     (A0),Line;                       UNTIL AnzLines>=Line
  168.   blo     LineLoop;
  169. ;
  170. ;------  That's it:  ------
  171. ;
  172.   bra.s   Ende;
  173. ;
  174. ;-------  Read one Byte:  ------
  175. ;                                        PROCEDURE GetByte();
  176. GetByte: ;                               BEGIN
  177.   move.b  0(Buffer,count),Scratch;         Scratch := Buffer^[count];
  178.   addq.w  #1,count;                        INC(count);
  179.   cmp.w   #512,count;
  180.   blo.s   BufferNotEmpty;                  IF count>=512 THEN
  181.   movem.l   D0-D7/A2-A6,-(sp);               PUSH(all);
  182.   jsr     (GetData);                         GetData();
  183.   movem.l   (sp)+,D0-D7/A2-A6;               PULL(all);
  184.   clr     count;                             count := 0;
  185. BufferNotEmpty: ;                          END;
  186.   rts;                                   END GetByte;
  187. ;
  188. ;------  Memory for Variables:  ------
  189. ;                                        VAR
  190. Extra: dc.w 1;                             Extra: BOOLEAN;
  191. AnzLines: dc.w 1;                          AnzLines: INTEGER;
  192.  
  193. Ende:
  194.   end
  195.